import axios from '@/utils/request'
export default {
  StoreProduct: {
    entity: { name: 'StoreSpecification', prefix: () => `store/${localStorage.getItem('storeId')}` },
    list: {
      // actions: [
      //   {
      //     name: '导入修改成本',
      //     position: 'top',
      //     component:
      //       () => import('@/views/store-product/add-store-products-batch.vue')
      //   }
      // ],
      export: {
        query: {
          '@display': `{
            'id' : 'entity.getId()',
            'product' : 'entity.getSpecification().__toString()',
            'price' : 'entity.getPrice()'
          }`,
          limit: 10000000
        },
        label: {
          'id': 'Id',
          'product': '产品',
          'price': '成本'
        }
      },
      disabled_actions: ['new', 'delete'],
      list_filter: {
        'specification.product.category.id': () => {
          return axios
            .get(`/api/categories`,
              { params: { '@filter': 'entity.getParent() && entity.getType().getSlug() == "ProductCategory"', '@expands': "['entity.parent']" } })
            .then(res =>
              Object.assign(
                { __label: '产品分类' },
                ...res.data.map(v => { return { [v.id]: `${v.name}(${v.parent.__toString})` } })
              )
            )
        },
        'specification.product.name': '产品'
      },
      list_display: [
        'specification',
        {
          property: 'price',
          label: '成本',
          editable: true
        },
        {
          property: 'enabled',
          label: '上架',
          editable: true
        }
        // 'enabled'
      ]
    },
    form: {
      fields: '__all__'
    }
  }
}

